﻿using System;
using System.Runtime.Serialization;

namespace DependencyAnalysis.DataModel
{
    [Serializable]
    [DataContract(IsReference = true)]
    [KnownType(typeof(MemberDescriptor))]
    [KnownType(typeof(ReferenceType))]
    public class DependencyDescriptor : IDescriptor
    {
        [DataMember(Order = 1)]
        public string Identifier { get; set; }

        public string FullName { get { return Identifier; } }

        [DataMember(Order = 2)]
        public MemberDescriptor Target { get; set; }

        [DataMember(Order = 3)]
        public MemberDescriptor Source { get; set; }

        public IDescriptor Parent { get { return null; } }

        [DataMember(Order = 4)]
        public ReferenceType ReferenceType { get; set; }

        public override bool Equals(object obj)
        {
            if (!(obj is DependencyDescriptor)) return false;

            return String.Equals(Identifier, ((DependencyDescriptor)obj).Identifier);
        }

        public override int GetHashCode()
        {
            return ("" + Identifier).GetHashCode();
        }

        public override string ToString()
        {
            return GetType().Name + ": " + Source + " -> " + Target;
        }
    }
}
